﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Scheduling.Models;
using Scheduling.Models.Repos.Database;
using Scheduling.Models.Interfaces;

namespace Scheduling.Controllers
{
    public class CourseController : BaseController
    {
        /// <summary>
        /// Listing all the courses.
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult List()
        {
            return View(new List<Course>());
        }


        [HttpPost]
        public ActionResult List(string inSearchCoursePattern)
        {
            var courseLoader = IoC.Resolve<ICourseLoader>();
            ViewData["inSearchCoursePattern"] = inSearchCoursePattern;
            return View(courseLoader.SearchCoursesByPatten(inSearchCoursePattern).Take(50));
        }

        [HttpGet]
        public ActionResult Show(string id)
        {
            var courseLoader = IoC.Resolve<ICourseLoader>();
            var course = courseLoader.GetCourseByID(id);

            if (course == null)
                FileNotFound();

            var courseInstanceLoader = IoC.Resolve<ICourseInstanceLoader>();
            ViewData["CourseInstances"] = courseInstanceLoader.GetCourseInstancesByCourseID(id);

            return View(course);
        }

        [HttpGet]
        public ActionResult ListBookings(string id)
        {
            ViewData["Course"] = id;
            var bookingLoader = IoC.Resolve<IBookingLoader>();
            var bookinglist = bookingLoader.GetBookingByCourseID(id);
            return View(bookinglist);
        }

    }
}
